package core

import (
	"gitee.com/gitee-go/core/common"
	"github.com/sirupsen/logrus"
	"path/filepath"
)

var Log = logrus.New()
var LogPnc = logrus.New()

func InitLog(path string) {
	if path == "" {
		path = "logs"
	}
	pmp := PathMap{
		logrus.InfoLevel:  filepath.Join(path, "info.log"),
		logrus.WarnLevel:  filepath.Join(path, "warn.log"),
		logrus.ErrorLevel: filepath.Join(path, "error.log"),
	}
	if common.IsDebug {
		pmp[logrus.DebugLevel] = filepath.Join(path, "debug.log")
		Log.SetLevel(logrus.DebugLevel)
	} else {
		Log.SetLevel(logrus.InfoLevel)
	}
	Log.AddHook(NewLfsHook(pmp, &logrus.TextFormatter{}))
	pmp = PathMap{
		logrus.ErrorLevel: filepath.Join(path, "panic.log"),
	}
	LogPnc.SetLevel(logrus.ErrorLevel)
	LogPnc.AddHook(NewLfsHook(pmp, &logrus.TextFormatter{}))
}
